<?php

/**
 * This is the model class for table "toko".
 *
 * The followings are the available columns in table 'toko':
 * @property integer $KODE_TOKO
 * @property string $ID_USER
 * @property string $ID_KOTA
 * @property string $NAMA_TOKO
 * @property string $ALAMAT_TOKO
 *
 * The followings are the available model relations:
 * @property Produk[] $produks
 * @property Kota $iDKOTA
 * @property User $iDUSER
 * @property User[] $users
 */
class Toko extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Toko the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'toko';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('KODE_TOKO, ID_USER, NAMA_TOKO, ALAMAT_TOKO', 'required'),
			array('KODE_TOKO', 'numerical', 'integerOnly'=>true),
			array('ID_USER', 'length', 'max'=>8),
			array('ID_KOTA', 'length', 'max'=>40),
			array('NAMA_TOKO', 'length', 'max'=>25),
			array('ALAMAT_TOKO', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('KODE_TOKO, ID_USER, ID_KOTA, NAMA_TOKO, ALAMAT_TOKO', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'produks' => array(self::HAS_MANY, 'Produk', 'KODE_TOKO'),
			'iDKOTA' => array(self::BELONGS_TO, 'Kota', 'ID_KOTA'),
			'iDUSER' => array(self::BELONGS_TO, 'User', 'ID_USER'),
			'users' => array(self::HAS_MANY, 'User', 'KODE_TOKO'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'KODE_TOKO' => 'Kode Toko',
			'ID_USER' => 'Id User',
			'ID_KOTA' => 'Id Kota',
			'NAMA_TOKO' => 'Nama Toko',
			'ALAMAT_TOKO' => 'Alamat Toko',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('KODE_TOKO',$this->KODE_TOKO);
		$criteria->compare('ID_USER',$this->ID_USER,true);
		$criteria->compare('ID_KOTA',$this->ID_KOTA,true);
		$criteria->compare('NAMA_TOKO',$this->NAMA_TOKO,true);
		$criteria->compare('ALAMAT_TOKO',$this->ALAMAT_TOKO,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}